package com.javasm.controller.goodsController;

import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.goodsCriteria.PaPriceAdministrationCriteria;
import com.javasm.domin.entity.goodsEntity.PaPriceAdministration;
import com.javasm.domin.vo.goodsVo.PaPriceAdministrationVo;
import com.javasm.service.goodsService.PaPriceAdministrationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/11/25-17:23
 * @Since:jdk1.8
 * @Description:
 */
@RestController
@RequestMapping("/paPriceAdministration")
@RequiredArgsConstructor
public class PaPriceAdministrationController extends BaseController {

    private final PaPriceAdministrationService paPriceAdministrationService;

    /**
     * 查所有
     */
    @GetMapping("findList")
    public AxiosResult<PageResult<PaPriceAdministrationVo>> list(PaPriceAdministrationCriteria paPriceAdministrationCriteria){

        return AxiosResult.success(paPriceAdministrationService.searchPage(paPriceAdministrationCriteria));

    }


    @PostMapping("add")
    public AxiosResult add(@RequestBody PaPriceAdministration paPriceAdministration){

        System.out.println("============"+paPriceAdministration.toString());

        paPriceAdministration.setReviewer("admin");
        paPriceAdministration.setId(null);
        paPriceAdministration.setAuditStatus("未审核");
        return AxiosResult.success(paPriceAdministrationService.save(paPriceAdministration));

    }

    @PutMapping("updatePrice")
    public AxiosResult updatePrice(@RequestBody PaPriceAdministration paPriceAdministration){

        System.out.println("============"+paPriceAdministration.getId());

        return AxiosResult.success(paPriceAdministrationService.updateById(paPriceAdministration));

    }

    @DeleteMapping("deleteById/{id}")
    public AxiosResult deleteById(@PathVariable Long id){

        return AxiosResult.success(paPriceAdministrationService.removeById(id));

    }

    @DeleteMapping("batchDeleteIds/{ids}")
    public AxiosResult batchDeleteIds(@PathVariable List<Long> ids){

        return toAxios(paPriceAdministrationService.batchDeleteIds(ids));
    }

    @PutMapping("updatePricePass")
    public AxiosResult updatePricepass(@RequestBody PaPriceAdministration paPriceAdministration){

        paPriceAdministration.setAuditStatus("已审核");

        System.out.println("============"+paPriceAdministration.getId());

        return AxiosResult.success(paPriceAdministrationService.updateById(paPriceAdministration));

    }
    @PutMapping("updatePriceNoPass")
    public AxiosResult updatePriceNoPass(@RequestBody PaPriceAdministration paPriceAdministration){
        paPriceAdministration.setAuditStatus("审核未通过");
        System.out.println("============"+paPriceAdministration.getId());

        return AxiosResult.success(paPriceAdministrationService.updateById(paPriceAdministration));

    }

}
